package com.xy.annotaion.handler.kotlin

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.jsoup.Jsoup

//expect external fun f()
suspend fun suspend_f() {
    p("suspend")
}

class A {
    var a = 100

}

fun f1(): () -> Unit {

    var x = 0

    return fun() {
        x++
        p("x = $x")
    }
}

fun main() {

    p("spider 3")

//    val con = Jsoup.connect("https://www.baidu.com")
//
//    val r = con.execute()
//    p(r.body())
//    val doc = con.get()
//    p(doc.getElementsByTag("kd"))

    val con2 = Jsoup.connect(
        "http://www.useragentstring.com/?uas=Opera/9.70%20(Linux%20i686%20;%20U;%20en-us)%20Presto/2.2.0&getJSON=all"
    )
    val doc2 = con2.ignoreContentType(true).get()
    p(doc2.text())

    runBlocking {
        launch {
            p("coroutines")
        }
    }

//    suspend_f()

    val c = object {
        val a = 123
    }

    p(c)


    val closure = f1()
    closure()
    closure()
    closure()

    val a = A()
    a.a = 100
    var b = A()
    b.a = 300
    p(a.a, b.a)

//    var cv = [1,3,5]

    var k1 = 1

    k1 shl 2

    GlobalScope.launch(Dispatchers.Main) {
        p("GlobalScope.launch")
    }


}